package com.kaka.bus.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.kaka.bus.R;
import com.kaka.bus.constant.UserConstant;


/**
 * Created by zhangqi on 2016/10/25.
 */

public class AuthView extends FrameLayout {

    private TextView mInfo;
    private ImageView mIcon;
    private TextView mTips;

    public AuthView(Context context) {
        this(context,null);
    }

    public AuthView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public AuthView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setBackgroundResource(R.drawable.layout_ripple_white);
        setClickable(true);
        initView();

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AuthView);
        String info = a.getString(R.styleable.AuthView_item_auth);
        int info_icon = a.getResourceId(R.styleable.AuthView_item_auth_icon,-1);

        mInfo.setText(info);
        if(!(info_icon == -1)){
            mIcon.setImageResource(info_icon);
        }

        a.recycle();
    }

    public void setTips(String text,String ns){
        mTips.setText(text);
        mTips.setBackgroundResource(R.drawable.auth_tv_bg_t);
        if(UserConstant.NS002.equals(ns)){
            mTips.setTextColor(Color.parseColor("#81DA59"));
        }else if(UserConstant.NS004.equals(ns)){
            mTips.setTextColor(Color.parseColor("#538CFF"));
        }else if(UserConstant.NS001.equals(ns)){
            mTips.setTextColor(Color.parseColor("#999999"));
        }else if(UserConstant.NS005.equals(ns)){
            mTips.setTextColor(Color.parseColor("#F66536"));
        }else if(UserConstant.NS006.equals(ns)){
            mTips.setTextColor(Color.parseColor("#999999"));
            mTips.setBackgroundResource(R.drawable.auth_tv_bg);
        }
    }

    private void initView() {
        View.inflate(getContext(), R.layout.item_auth,this);

        mInfo = findViewById(R.id.item_tv_auth);
        mIcon = findViewById(R.id.item_iv_auth_icon);
        mTips = findViewById(R.id.item_iv_auth_tips);
    }

}
